package com.rongxun.hbwallet.ui.activities;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.rongxun.base.MvpActivity;
import com.rongxun.hbwallet.R;
import com.rongxun.hbwallet.model.entity.SubCate;
import com.rongxun.hbwallet.mvp.contract.ISweetDetail;
import com.rongxun.hbwallet.mvp.model.ApiModel;
import com.rongxun.hbwallet.mvp.presenter.SweetDetailPresenter;
import com.rongxun.hbwallet.ui.adapter.ResumeAdapter;
import com.rongxun.utils.StatusBarUtil;
import com.rongxun.widget.LoadingDialog;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 创建者     庄丰泽
 * 创建时间   2018/8/9 16:48
 * 描述	     糖果明细
 */
public class SweetDetailActivity extends MvpActivity<ISweetDetail.IView,SweetDetailPresenter> implements ISweetDetail.IView {
    @BindView(R.id.resume_rv)
    RecyclerView mRecyclerView;
    @BindView(R.id.toolbar_back)
    ImageView    mToolbarBack;
    @BindView(R.id.toolbar_title)
    TextView     mToolbarTitle;
    @BindView(R.id.toolbar)
    Toolbar      mToolbar;
    private ResumeAdapter mAdapter;
    private List<SubCate>                                 mList;
    private Dialog                                        mLoadingDialog;
    @Override
    protected void init() {
        mToolbarTitle.setText(getString(R.string.sweet_detail));
        mToolbarBack.setVisibility(View.VISIBLE);
        mLoadingDialog = LoadingDialog.createLoadingDialog(this, "加载中", false);
        StatusBarUtil.setToolBarPaddingTop(mToolbar, this);
        getPresenter().showSelection();
    }
    @Override
    protected int getContentView() {
        return R.layout.activity_resume;
    }

    @NonNull
    @Override
    public SweetDetailPresenter createPresenter() {
        return new SweetDetailPresenter(this,new ApiModel(this));
    }

    @Override
    public void showSelection(List<SubCate> subCates) {
        mAdapter=new ResumeAdapter(subCates);
        LinearLayoutManager manager=new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(manager);
        mRecyclerView.setAdapter(mAdapter);
    }



    @Override
    public Context getContext() {
        return this;
    }

    @Override
    public void showLoading(boolean show) {
        if(show){
            mLoadingDialog.show();
        }else{
            mLoadingDialog.cancel();
        }
    }

    @Override
    public void showError(String msg, String errorCode) {

    }

    @Override
    public void checkPermissionsSuccessful(String... permissions) {

    }

    @Override
    public void release() {

    }
    @OnClick(R.id.toolbar_back)
    public  void onViewClicked(View view){
        if(view.getId()==R.id.toolbar_back){
            onBackPressed();
        }
    }
}
